package com.huike.business.service.impl;

import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.vo.TbBusinessTrackRecordVo;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Author: qingtao
 * @Date 2022/3/31 15:37
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    @Override
    public List<TbBusinessTrackRecord> list(Long businessId) {
        return tbBusinessTrackRecordMapper.list(businessId);
    }


    /**
     * 添加商机记录
     * @return
     */
    @Override
    @Transactional
    public boolean saveBusinessTrackRecordService(TbBusinessTrackRecord tbBusinessTrackRecord, TbBusiness tbBusiness) {
        tbBusinessTrackRecord.setCreateBy(SecurityUtils.getUsername());//跟进人
        tbBusinessTrackRecord.setCreateTime(new Date());//跟进时间
        tbBusinessTrackRecordMapper.saveBusinessTrackRecordService(tbBusinessTrackRecord);
        tbBusiness.setId(tbBusinessTrackRecord.getBusinessId());
        tbBusiness.setStatus("2");
        tbBusinessMapper.updateTbBusiness(tbBusiness);
        return true;

    }
}
